<?php
/**
 *Bic_Cache
 * @package Bic
 * @author Bic
 * @version $Id:  2010-12-29
 * @copyright (c) 2010 Bic
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
 * Minimum Requirement: PHP 5.2.+
 */
if (! defined ( 'IN_BIC' )) {
    die ( '非法缓存访问来源!' );
}
class Bic_Cache extends Bic_Base{

    public static $_defaultConfig = array(
        '_path' => '',
        /**
         *缓存时间。(秒)
         * @var <type> 
         */
        '_lifeTime'=>60
        );
    public static $_config = array();
    
    /**
     *Cache engine obj.
     * @var type 
     */
    private static $_cacheEngine = array();
    private static $_engine = null;
    private static $_engineName = null;
    
    private function __construct() { }
    
    /**
     *工厂方法
     * @param string $engine  file of default.
     * @param array $customConfig    
     * @return \Bic_Cache_Drivers_File 
     */
    public static function create( $engine='file', $customConfig=array()){
        self :: $_config = array_merge(self :: $_defaultConfig, $customConfig);
        switch ($engine){
            /**
             * 文件缓存引擎
             */
            case 'file':
            default:
                self :: $_engineName = 'file';  //注册引擎名称
                self :: $_engine = new Bic_Cache_Drivers_File(0, self::$_config);
                break;
        }
        
        if(!is_null(self :: $_engine)) return self :: $_engine;
        
        throw new Bic_Exception("No $engine of engine found.");
    }
    
    /**
     *获取当前缓存引擎
     * @return type 
     */
    public function getEngine(){
        return self :: $_engine;
    }
    
    public function getEngineName(){
        return self :: $_engineName;
    }
    
    public function setEngine($engine){
        
        switch ($engine){
            
            /**
             * 文件缓存引擎
             */
            case 'file':
            default:
                $this -> _engineName = 'file';  //注册引擎名称
                self :: $_cacheEngine[$this -> _engineName] = new Bic_Cache_FileDriver($cacheName, $lifeTime, $groupName, $this -> _config);
                break;
        }
    }

}

?>
